home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / Draw / Sources / RectShp.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  7.0 KB  |  275 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                RectShp.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef BASESHP_H
  15. #include "BaseShp.h"
  16. #endif
  17.  
  18. #ifndef BOUNDSHP_H
  19. #include "BoundShp.h"
  20. #endif
  21.  
  22. #ifndef RECTSHP_H
  23. #include "RectShp.h"
  24. #endif
  25.  
  26. #ifndef UTILS_H
  27. #include "Utils.h"
  28. #endif
  29.  
  30. #ifndef CONSTANT_H
  31. #include "Constant.h"
  32. #endif
  33.  
  34. #ifndef DRAWPART_H
  35. #include "DrawPart.h"
  36. #endif
  37.  
  38. #ifndef DRAWPART_H
  39. #include "DrawPart.h"
  40. #endif
  41.  
  42. #ifndef DRAWFRM_H
  43. #include "DrawFrm.h"
  44. #endif
  45.  
  46. #ifndef DRAWPRXY_H
  47. #include "DrawPrxy.h"
  48. #endif
  49.  
  50. #ifndef DRAWLINK_H
  51. #include "DrawLink.h"
  52. #endif
  53.  
  54. #ifndef DRAWCLIP_H
  55. #include "DrawClip.h"
  56. #endif
  57.  
  58. // ----- Part Layer -----
  59.  
  60. #ifndef FWFRMING_H
  61. #include "FWFrming.h"
  62. #endif
  63.  
  64. #ifndef FWUTIL_H
  65. #include "FWUtil.h"
  66. #endif
  67.  
  68. #ifndef FWSELECT_H
  69. #include "FWSelect.h"
  70. #endif
  71.  
  72. #ifndef FWITERS_H
  73. #include "FWIters.h"
  74. #endif
  75.  
  76. // ----- OS Layer -----
  77.  
  78. #ifndef FWEVENT_H
  79. #include "FWEvent.h"
  80. #endif
  81.  
  82. #ifndef FWRECSHP_H
  83. #include "FWRecShp.h"
  84. #endif
  85.  
  86. #ifndef FWTXTBOX_H
  87. #include "FWTxtBox.h"
  88. #endif
  89.  
  90. #ifndef FWLINSHP_H
  91. #include "FWLinShp.h"
  92. #endif
  93.  
  94. #ifndef FWOVLSHP_H
  95. #include "FWOvlShp.h"
  96. #endif
  97.  
  98. #ifndef FWRRCSHP_H
  99. #include "FWRRcShp.h"
  100. #endif
  101.  
  102. #ifndef FWODGEOM_H
  103. #include "FWODGeom.h"
  104. #endif
  105.  
  106. // ----- Foundation Includes -----
  107.  
  108. #ifndef FWSTREAM_H
  109. #include "FWStream.h"
  110. #endif
  111.  
  112. // ----- OpenDoc Includes -----
  113.  
  114. #ifndef SOM_ODTransform_xh
  115. #include <Trnsform.xh>
  116. #endif
  117.  
  118. //========================================================================================
  119. // Runtime Information
  120. //========================================================================================
  121.  
  122. #ifdef FW_BUILD_MAC
  123. #pragma segment odfdrawshapes
  124. #endif
  125.  
  126. //========================================================================================
  127. // RunTime Info
  128. //========================================================================================
  129.  
  130. FW_DEFINE_AUTO(CRectShape)
  131. FW_DEFINE_CLASS_M1(CRectShape, CBoundedShape)
  132.  
  133. const FW_ClassTypeConstant LRectShape = FW_TYPE_CONSTANT('s','h','r','c');
  134. FW_REGISTER_ARCHIVABLE_CLASS(LRectShape, CRectShape, CRectShape::Read, 0, 0, CBaseShape::Write)
  135.  
  136. //========================================================================================
  137. // class CRectShape
  138. //========================================================================================
  139.  
  140. //----------------------------------------------------------------------------------------
  141. // CRectShape::CRectShape
  142. //----------------------------------------------------------------------------------------
  143.  
  144. CRectShape::CRectShape() :
  145.     CBoundedShape(kRectShape, kFrameOnly)
  146. {
  147.     FW_END_CONSTRUCTOR
  148. }
  149.  
  150. //----------------------------------------------------------------------------------------
  151. // CRectShape::CRectShape
  152. //----------------------------------------------------------------------------------------
  153.  
  154. CRectShape::CRectShape(unsigned short shapeType, unsigned short renderVerb) :
  155.     CBoundedShape(shapeType, renderVerb)
  156. {
  157.     FW_END_CONSTRUCTOR
  158. }
  159.  
  160. //----------------------------------------------------------------------------------------
  161. // CRectShape::CRectShape
  162. //----------------------------------------------------------------------------------------
  163.  
  164. CRectShape::CRectShape(FW_CReadableStream& archive) :
  165.     CBoundedShape(archive)
  166. {    
  167.     FW_END_CONSTRUCTOR
  168. }
  169.  
  170. //----------------------------------------------------------------------------------------
  171. // CRectShape::~CRectShape
  172. //----------------------------------------------------------------------------------------
  173.  
  174. CRectShape::~CRectShape()
  175. {
  176.     FW_START_DESTRUCTOR
  177. }
  178.  
  179. //----------------------------------------------------------------------------------------
  180. // CRectShape::RenderShape
  181. //----------------------------------------------------------------------------------------
  182.  
  183. void CRectShape::RenderShape(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc)
  184. {
  185.     FW_CRect rect = GetRectGeometry();
  186.     AdjustRectForPenSize(rect, GetPenSize());
  187.  
  188.     if (HasFillStyle())
  189.         FW_CRectShape::RenderRect(gc, rect, FW_kFill, fFillInk, fFillStyle);
  190.     
  191.     if (HasFrameStyle())
  192.         FW_CRectShape::RenderRect(gc, rect, FW_kFrame, fFrameInk, fFrameStyle);
  193. }
  194.  
  195. //----------------------------------------------------------------------------------------
  196. // CRectShape::HitTest
  197. //----------------------------------------------------------------------------------------
  198.  
  199. FW_Boolean CRectShape::HitTest(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent) const
  200. {
  201.     FW_CPoint mouse = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  202.     ODFacet* facet = theMouseEvent.GetFacet(ev);
  203.     FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  204.     frame->GetContentView(ev)->FrameToViewContent(ev, mouse);
  205.     
  206.     FW_CRect bounds = GetRectGeometry();
  207.     AdjustRectForPenSize(bounds, GetPenSize());
  208.  
  209.     FW_CRectShape rectShape(bounds, HasFillStyle() ? FW_kFill : FW_kFrame);
  210.     return rectShape.HitTest(gc, mouse, FW_IntToFixed(2));
  211. }
  212.  
  213. //----------------------------------------------------------------------------------------
  214. // CRectShape::OutlineShape
  215. //----------------------------------------------------------------------------------------
  216.  
  217. void CRectShape::OutlineShape(FW_CGraphicContext& gc, const FW_CInk& ink, const FW_CStyle& style, const FW_CRect& rect)
  218. {
  219.     FW_CRect bounds(rect);
  220.     AdjustRectForPenSize(bounds, style.GetPenSize());
  221.     FW_CRectShape::RenderRect(gc,
  222.                               bounds,
  223.                               FW_kFrame,
  224.                               ink, style);
  225. }
  226.  
  227. //----------------------------------------------------------------------------------------
  228. // CRectShape::GetClipRegion
  229. //----------------------------------------------------------------------------------------
  230.  
  231. void CRectShape::GetClipRegion(Environment *ev, ODShape* clipRegion)
  232. {
  233.     FW_CRect bounds = GetRectGeometry();
  234.     AdjustRectForPenSize(bounds, GetPenSize());
  235.     
  236.     ODRect odBounds = bounds;
  237.     clipRegion->SetRectangle(ev, &odBounds);
  238.     
  239.     if (FrameOnly())
  240.     {
  241.         bounds.Inset(GetPenSize(), GetPenSize());
  242.         
  243.         FW_CAcquiredODShape aqTempShape = ::FW_NewODShape(ev, bounds);
  244.         clipRegion->Subtract(ev, aqTempShape);
  245.     }
  246. }
  247.  
  248. //----------------------------------------------------------------------------------------
  249. // CRectShape::CreateShapeOutline
  250. //----------------------------------------------------------------------------------------
  251.  
  252. ODShape* CRectShape::CreateShapeOutline(Environment *ev)
  253. {
  254.     FW_CRect bounds = GetRectGeometry();
  255.     AdjustRectForPenSize(bounds, GetPenSize());
  256.  
  257.         // We don't acquire it because we return it
  258.     ODShape* dragRgn = ::FW_NewODShape(ev, bounds);
  259.  
  260.     ::FW_OutlineODShape(ev, dragRgn, GetPenSize());
  261.  
  262.     return dragRgn;
  263. }
  264.  
  265. //----------------------------------------------------------------------------------------
  266. // CRectShape::Read
  267. //----------------------------------------------------------------------------------------
  268.  
  269. void* CRectShape::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  270. {
  271. FW_UNUSED(type);
  272.     return FW_NEW(CRectShape, (stream));
  273. }
  274.  
  275.